﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;

namespace _5_NovaAdmin.Infrastructure.Persistence.Repositories
{
    /// <summary>
    /// 复合主键泛型仓储（复合主键）
    /// </summary>
    /// <typeparam name="TEntity"></typeparam>
    public class CompositeRepository<TEntity> : CompositeRepository<TEntity, Guid>, ICompositeRepository<TEntity>
        where TEntity : CompositeEntity<Guid>
    {
        public CompositeRepository(AppDbContext Mddb) : base(Mddb)
        {
        }
    }

    /// <summary>
    /// 复合主键泛型仓储（复合主键）
    /// </summary>
    /// <typeparam name="TEntity"></typeparam>
    /// <typeparam name="TKey"></typeparam>
    public class CompositeRepository<TEntity, TKey> : BaseRepository<TEntity>, ICompositeRepository<TEntity, TKey>
    where TEntity : CompositeEntity<TKey>
    where TKey : notnull
    {
        public CompositeRepository(AppDbContext Mddb) : base(Mddb)
        {

        }

        public Task<bool> InsertManyData(List<TEntity> array)
        {
            throw new NotImplementedException();
        }

        public Task<Tuple<bool, int>> InsertOrUpdateSingleData(TEntity data)
        {
            throw new NotImplementedException();
        }

        public async Task InsertSingleData(TEntity data)
        {
            ITokenHandler tokenHandler = _Mddb.serviceProvider.GetRequiredService<ITokenHandler>();
            var createOpId = await tokenHandler.GetClaimValueAsync<TKey>(ClaimTypes.NameIdentifier);
            var createOpName = await tokenHandler.GetClaimValueAsync<string>(ClaimTypes.Name);
            var creationAudit = new _3_NovaAdmin.Domain.ValueObjects.CreationAuditInfo<TKey>(createOpId, createOpName, DateTime.Now);
            data.ChangeCreationAudit(creationAudit);
            await Entity.AddAsync(data);
        }

        public Task<TEntity> QuerySingleData(TKey id)
        {
            throw new NotImplementedException();
        }

        public Task UpdateSingleData(TEntity data)
        {
            throw new NotImplementedException();
        }
    }
}
